package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/jmoiron/sqlx"
	"vip_video/configx"
	"vip_video/internal/library"
	"vip_video/models"
)

type SwiperController struct {
	Db     *sqlx.DB
	Config *configx.Config
}

func NewSwiperController() *SwiperController {
	return &SwiperController{}
}

func (sc *SwiperController) WithDb(db *sqlx.DB) *SwiperController {
	sc.Db = db
	return sc
}

func (sc *SwiperController) WithConfig(config *configx.Config) *SwiperController {
	sc.Config = config
	return sc
}

func (sc *SwiperController) Index(ctx *gin.Context) {
	response := library.NewResponse(ctx)
	var list []*models.SwiperModel
	_ = sc.Db.Select(
		&list,
		"select * from fa_swiper",
	)
	for _, model := range list {
		model.Thumb = model.FullThumb()
	}
	response.Success(
		"",
		list,
	)
	return
}
